<template>
	<view class="container">
		<view class="list-area">
			<yxyl-album-item-list spOpt="true" :itemList="timeTableList" :currentIndex="currentIndex"  @change="change"></yxyl-album-item-list>
		</view>
	</view>
</template>

<script>
import yxylAlbumItemList from '@/components/yxyl-album-tabs/yxyl-album-itemList.vue';
export default {
	name: 'subList',
	components: { yxylAlbumItemList },
	data(){
		return{
			timeTableList: [],
			currentIndex: -1,
			param: {}
		}
	},
	onLoad(e){
		this.getLivePlayList(e.classId)
		this.param = e
	},
	methods: {	
		getLivePlayList(id) {
			return this.$http
				.request({
					url: 'api/LivePlayer/GetLivePlayListById',
					data: {
						Id: id
					}
				})
				.then(res => {
					var that = this;
					let title = res.courseName;
					if(that.param.dist == 0){
						title += '-作业区'
					}else if(that.param.dist == 1){
						title += '-预习区'
					}else if(that.param.dist == 2){
						title += '-签到区'
					}
					uni.setNavigationBarTitle({
					　　title: title
					})
					// 作业区
					if(that.param.dist == 0){
						res.timeTables.forEach(function(item, index) {
							that.timeTableList.push({
								isReview: item.classStatus == 3,
								itemTitle: item.title,
								id: item.id,
								show: item.homeworkListShow
							})
						})
					}
					// 预习区
					else if(that.param.dist == 1){
						res.timeTables.forEach(function(item, index) {
							that.timeTableList.push({
								isReview: item.classStatus == 3,
								itemTitle: item.title,
								id: item.id,
								show: item.previewListShow
							})
						})
					}
					// 签到列表
					else if(that.param.dist == 2){
						res.timeTables.forEach(function(item, index) {
							that.timeTableList.push({
								isReview: item.classStatus == 3,
								itemTitle: item.title,
								id: item.id,
								show: item.checkListListShow
							})
						})
					}
				})
		},
		change(e) {
			this.currentIndex = e;
			this.goItem();
		},
		goItem(){
			let currentItem = this.timeTableList[this.currentIndex]
			// 作业区
			if(this.param.dist == 0){
				uni.navigateTo({
					url: `../meiPianList/homeworkList?mainId=${currentItem.id}&courseName=${this.param.courseName}&classId=${this.param.classId}`
				})
			}
			// 预习区
			else if(this.param.dist == 1){
				this.$http.request({
					url: 'api/Essay/CheckByMainId',
					method: 'GET',
					showLoading: false,
					data:{
						Id: currentItem.id,
						EssayType: 1	//1：老师布置的预习作业
					}
				}).then(resp=>{
					if(resp.essayId){
						uni.navigateTo({
							url: `../meiPianList/previewList?essayId=${resp.essayId}&essayType=1&courseName=${this.param.courseName}&classId=${this.param.classId}&timeTableId=${currentItem.id}`
						})
					}else{
						uni.navigateTo({
							url: `../meipian/meipian?&isEditor=false&essayType=${this.param.essayType}&mainId=${currentItem.id}`
						})
					}
				})
			}
			// 签到区
			else if(this.param.dist == 2){
				uni.navigateTo({
					url: `../singInfo/singInfo?id=${currentItem.id}`
				})
			}
		}
	}
};
</script>

<style lang="scss" scoped>
	.container{
		
	}
</style>
